package com.xbongbong.saas.enums;

import lombok.Getter;

import java.util.Objects;

/**
 * @author cyy
 * @version v1.0
 * @date
 * @since v1.0
 */
@Getter
public enum BusinessProductTableNameEnum {

    /**
     * 盘点单
     */
    INVENTORY_PRODUCT(XbbRefTypeEnum.INVENTORY.getCode(),"tb_saas_inventory_product","inventory_id"),
    OPPORTUNITY_PRODUCT(XbbRefTypeEnum.SALES_OPPORTUNITY.getCode(),"tb_saas_opportunity_product","opportunity_id"),
    CONTRACT_PRODUCT(XbbRefTypeEnum.CONTRACT.getCode(),"tb_saas_contract_product","contract_id"),
    PURCHASE_PRODUCT(XbbRefTypeEnum.PURCHASE.getCode(),"tb_saas_purchase_product","purchase_sheet_id"),
    TRANSFER_PRODUCT(XbbRefTypeEnum.TRANSFER.getCode(),"tb_saas_transfer_product","transfer_id"),
    ASSEMBLE_PRODUCT(XbbRefTypeEnum.ASSEMBLE.getCode(),"tb_saas_assemble_product","assemble_id"),
    WORKORDER_PRODUCT(XbbRefTypeEnum.WORK_ORDER.getCode(),"tb_work_order_product","work_order_id"),
    RETURNEDPURCHASE_PRODUCT(XbbRefTypeEnum.RETURNED_PURCHASE.getCode(),"tb_saas_returned_purchase_product","return_purchase_id"),
    BOM_BILL_PRODUCT(XbbRefTypeEnum.BOM_BILL.getCode(),"tb_saas_bom_product","bom_id"),
    PRODUCTION_ORDER_PRODUCT(XbbRefTypeEnum.PRODUCTION_ORDER.getCode(),"tb_saas_production_order_product","production_order_id"),
    // 供应商 退货退款 报价单
    SUPPLIER_PRODUCT(XbbRefTypeEnum.SUPPLIER.getCode(),"tb_saas_supplier_product","supplier_id"),
    REFUND_PRODUCT(XbbRefTypeEnum.REFUND.getCode(),"tb_saas_contract_product",""),
    QUOTATION_PRODUCT(XbbRefTypeEnum.QUOTATION.getCode(),"tb_saas_quotation_product","quotation_id"),

    PURCHASE_INSTOCK_PRODUCT(XbbRefTypeEnum.PURCHASE_INSTOCK.getCode(),"tb_saas_instock_product","into_warehouse_id"),
    REFUND_INSTOCK_PRODUCT(XbbRefTypeEnum.REFUND_INSTOCK.getCode(), "tb_saas_instock_product", "into_warehouse_id"),
    OTHER_INSTOCK_PRODUCT(XbbRefTypeEnum.OTHER_INSTOCK.getCode(), "tb_saas_instock_product", "into_warehouse_id"),
    PRODUCTION_INSTOCK_PRODUCT(XbbRefTypeEnum.PRODUCTION_INSTOCK.getCode(), "tb_saas_instock_product", "into_warehouse_id"),
    RETURNED_MATERIEL_INSTOCK_PRODUCT(XbbRefTypeEnum.RETURNED_MATERIEL_INSTOCK.getCode(), "tb_saas_instock_product", "into_warehouse_id"),

    CONTRACT_OUTSTOCK_PRODUCT(XbbRefTypeEnum.CONTRACT_OUTSTOCK.getCode(), "tb_saas_outstock_product", "out_warehouse_id"),
    RETURNED_PURCHASE_OUTSTOCK_PRODUCT(XbbRefTypeEnum.RETURNED_PURCHASE_OUTSTOCK.getCode(), "tb_saas_outstock_product", "out_warehouse_id"),
    OTHER_OUTSTOCK_PRODUCT(XbbRefTypeEnum.OTHER_OUTSTOCK.getCode(), "tb_saas_outstock_product", "out_warehouse_id"),
    PRODUCTION_MATERIEL_OUTSTOCK_PRODUCT(XbbRefTypeEnum.PRODUCTION_MATERIEL_OUTSTOCK.getCode(), "tb_saas_outstock_product", "out_warehouse_id"),
    WORK_ORDER_OUTSTOCK_PRODUCT(XbbRefTypeEnum.WORK_ORDER_OUTSTOCK.getCode(), "tb_saas_outstock_product", "out_warehouse_id"),
    COST_ADJUST_PRODUCT(XbbRefTypeEnum.COST_ADJUST.getCode(), "tb_saas_cost_adjust", "cost_adjust_id"),


    UNKONW(-1,"未知",""),
    ;
    /**
     * 业务标识
     */
    private int code;

    /**
     * 该业务关联产品数据所在的数据表
     */
    private String tableName;

    /**
     * 关联数据表的记录column
     */
    private String refIdKey;

    /**
     * 关联数据表的关联产品id的column
     */
    private String productId;

    BusinessProductTableNameEnum(int code, String tableName,String refIdKey) {
        this.code = code;
        this.tableName = tableName;
        this.refIdKey = refIdKey;
    }

    public static BusinessProductTableNameEnum getTableNameByCode(int code){
        for (BusinessProductTableNameEnum selectProductTableNameEnum : BusinessProductTableNameEnum.values()){
            if (Objects.equals(code,selectProductTableNameEnum.getCode())){
                return selectProductTableNameEnum;
            }
        }
        return UNKONW;
    }
}
